package com.hangwei.aicabinet;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.hangwei.aicabinet.adapter.DoorColorAdapter;
import com.hangwei.aicabinet.presenter.LogoutPresenter;
import com.hangwei.aicabinet.util.SPKey;
import com.hangwei.aicabinet.util.SPUtil;
import com.hangwei.aicabinet.util.ToastUtil;

public class LoginActivity extends BaseActivity {

    private ImageView mIvLogin;
    private DoorColorAdapter mDoorColorAdapter;
    private LogoutPresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        RecyclerView rvDoorColor = findViewById(R.id.rvDoorColor);

        String string = SPUtil.getString(SPKey.CABINET_NUM);
        if (TextUtils.isEmpty(string)) {
            ToastUtil.showCenterToast("无法判断柜子型号，请重新绑定");
            Intent intent10 = new Intent(LoginActivity.this, BindActivity.class);
            intent10.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent10);
            return;
        }
        mIvLogin = findViewById(R.id.ivLogin);
        final View rlView = findViewById(R.id.rlView);
        mIvLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                if (Build.VERSION.SDK_INT >= 21)
//                    startActivity(new Intent(LoginActivity.this, QRActivity.class),
//                            ActivityOptions.makeSceneTransitionAnimation(LoginActivity.this).toBundle());
//                else
                    startActivity(new Intent(LoginActivity.this, QRActivity.class));


//                finish();
//                startActivity(new Intent(LoginActivity.this,QRActivity.class));
//                overridePendingTransition(R.anim.in,R.anim.out);
            }
        });
        mPresenter = new LogoutPresenter(null);
        rvDoorColor.setLayoutManager(new GridLayoutManager(this, 2));
        mDoorColorAdapter = new DoorColorAdapter();
        rvDoorColor.setAdapter(mDoorColorAdapter);
//        refreshDoorView();
    }

    private void refreshDoorView() {
        mPresenter.getAdminDoorView(mDoorColorAdapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mPresenter!=null&&mDoorColorAdapter!=null)
            refreshDoorView();
    }
}
